﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PMQLCHH.DAO;
using System.Data;
using PMQLCHH.DTO;
namespace PMQLCHH.BUS
{
    class GoiHangBUS
    {
        public static DataTable LoadDSPhieuGoi()
        {

            return GoiHangDAO.LoadDSPhieuGoi();
        }
        public static string LayNgayLapPhieuTraCuNhat()
        {
            DataTable dt = GoiHangDAO.LayNgayLapPTCuNhat();
            string NgayLap = "1990/01/01";
            DateTime date = new DateTime();
            if (dt.Rows.Count > 0)
            {
                date = DateTime.Parse(dt.Rows[0]["NgayLap"].ToString());
                NgayLap = date.Month + "/" + date.Day + "/" + date.Year;
            }
            return NgayLap;
        }
        public static DataTable LocPhieuTra(string MaPT, string strTuNgay, string strDenNgay, int TrangThai)
        {
            return GoiHangDAO.LocPhieuTra(MaPT, strTuNgay, strDenNgay, TrangThai);
        }
        public static bool XoaTatCaCTPT()
        {
            return GoiHangDAO.XoaTatCaTrongCTPT();
        }
        public static bool XoaTatCaPT()
        {
            return GoiHangDAO.XoaTatCaTrongPT();
        }
        public static bool XoaCTPTTheoMaPT(PhieuGoiHangDTO pg)
        {
            return GoiHangDAO.XoaCTPhieuTraTheoMaPT(pg);
        }
        public static bool XoaPTTheoMaPT(PhieuGoiHangDTO pg)
        {
            return GoiHangDAO.XoaPhieuGoiTheoMaPT(pg);
        }
        public static DataTable LoadCTPTTheoMPT(PhieuGoiHangDTO pg)
        {
            return GoiHangDAO.LoadCTPTTheoMPT(pg);
        }
        public static bool CapNhatTrangThaiPG(PhieuGoiHangDTO pg)
        {
            return GoiHangDAO.CapNhatTrangThaiPhieuTra(pg);
        }
        public static bool CapNhatTrangThaiCTPG(PhieuGoiHangDTO pg)
        {
            return GoiHangDAO.CapNhatTrangThaiCTPhieuTra(pg);
        }
        public static bool UpDateTableMatHang(ChiTietPhieuGoiHangDTO ctpg)
        {
            return GoiHangDAO.UpDateTableMatHang(ctpg);
        }
        public static DataTable LoadTatCaNhaCungCap()
        {
            DataTable dt = NhaCungCapDAO.LoadListNhaCungCap();
            return dt;
        }
        public static string GetMaPhieuGoi()
        {
            DataTable dt_kt = GoiHangDAO.LoadDSPhieuGoi();
            string mapg = "";
            if (dt_kt.Rows.Count > 0)
            {

                DataTable dt = GoiHangDAO.GetMaGoiHangLonNhat();
                int t = int.Parse(dt.Rows[0]["MaPhieuGoiHang"].ToString().Substring(2)) + 1;
                mapg = "GH" + t.ToString();
            }
            else
            {
                mapg = "GH1000001";
            }
            return mapg;
        }
        public static bool insertTablePhieuTra(PhieuGoiHangDTO pg)
        {
            return GoiHangDAO.InSertTablePhieuTra(pg);
        }
        public static bool insertTableCTPT(ChiTietPhieuGoiHangDTO ctpg)
        {
            return GoiHangDAO.InSertTableChiTietPhieuGoi(ctpg);
        }
        public static int LaySoLuongTonTheoMaMH(MatHangDTO mh)
        {
            int slt = 0;
            foreach (DataRow row in GoiHangDAO.LaySoLuongTonTheoMaMatHang(mh).Rows)
            {
                slt = int.Parse(row["SoLuongTon"].ToString());
            }
            return slt;
        }
    }
}

